import os

class FileObject(str):
    
    __instance = None
    def __init__(self, filename):
        print FileObject.__instance
        try:
            if os.path.isfile(filename):
                print "Opening file", filename
                self.file = open(filename, 'r+')
            else:
                print "Creating file", filename
                self.file = open(filename, 'w+')
        except Exception as e:
            print e
    
    def __str__(self):
        return  "Class FileObject", self.filename 

    def deleteFile(self, filename):
        try:
            if os.isfile(filename):
                print 'Removing file', filename
        except Exception as e:
            raise e 
            
    def __del__(self):
        self.file.close()
        del self.file
    
    def __ne__(self, other):
        return len(self) != len(other)

    def __eq__(self,other):
        return len(self) == len(other)

    # if attrribute does not exist

class NumberObject(int):
    pass
         
try:
    x = FileObject("test.txt")
    y = FileObject("test1.txt")

except AttributeError as e:
    print "Error: ", e

#y = FileObject("test1.txt")

